package com.ravi.controller;

import com.github.pagehelper.PageInfo;
import com.ravi.model.query.CommonPageReq;
import com.ravi.model.resp.R;
import com.ravi.model.vo.CheckItemVo;
import com.ravi.service.intf.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class CheckItemController {

	@Autowired
	private CheckItemService checkItemService;

	@PostMapping("checkitem/all")
	public R getAllItemVos(@RequestBody CommonPageReq pageReq) {
		PageInfo<CheckItemVo> pageInfo = checkItemService.listItemsPage(pageReq.getPageNum(), pageReq.getPageSize());
		return R.ok().put("pageInfo", pageInfo);
	}

	@GetMapping("checkitem/search")
	public R getItemVosByRoomTypeName(@RequestParam String roomTypeName) {
		List<CheckItemVo> vos = checkItemService.getVosByRoomTypeName(roomTypeName);
		return R.ok().put("checkitems", vos);
	}

	@GetMapping("checkitem/search/{itemId}")
	public R getItemVosByItemId(@PathVariable Integer itemId) {
		List<CheckItemVo> vos = checkItemService.getVosByItemId(itemId);
		return R.ok().put("checkitems", vos);
	}

	@GetMapping("checkitem/searchKey")
	public R getItemVosByItemKeyword(@RequestParam String keyword) {
		List<CheckItemVo> vos = checkItemService.getVosByItemKeyword(keyword);
		return R.ok().put("checkitems", vos);
	}
}